//
//  ZWMarketLeftTableViewModel.m
//  aixianfeng
//
//  Created by zhaowei on 17/5/5.
//  Copyright © 2017年 zhaowei. All rights reserved.
//

#import "ZWMarketLeftTableViewModel.h"
#import "ZWMarketManager.h"

@implementation ZWMarketLeftTableViewModel

- (instancetype)init {
    self = [super init];
    if (self) {
        [self setup];
    }
    return self;
}


#pragma mark - 属性赋值 -
- (void)setup {
    NSDictionary *dict = [[ZWMarketManager sharedInstance] gainMarketInfomation];
    NSMutableArray *nameMutable = [NSMutableArray array];
    NSMutableArray *idMutable = [NSMutableArray array];
    NSMutableArray *cateMutable = [NSMutableArray array];
    for (int i=0;i<9;i++) {
        NSString *name = dict[@"data"][@"categories"][i][@"name"];
        NSString *listID = dict[@"data"][@"categories"][i][@"id"];
        
        const char *c = [name cStringUsingEncoding:NSISOLatin1StringEncoding];
        NSString *newName = [[NSString alloc] initWithCString:c encoding:NSUTF8StringEncoding];
        
        //添加到可变数组
        [idMutable addObject:listID];
        [nameMutable addObject:newName];
        
        
        NSArray *arr = dict[@"data"][@"categories"][i][@"cids"];
        NSMutableArray *categoryNameArr = [NSMutableArray array];
        for (NSDictionary *dict in arr) {
            NSString *str = dict[@"name"];
            const char *c = [str cStringUsingEncoding:NSISOLatin1StringEncoding];
            NSString *name = [[NSString alloc] initWithCString:c encoding:NSUTF8StringEncoding];
            [categoryNameArr addObject:name];
        }
        
        [cateMutable addObject:categoryNameArr];
        
    }
    //列表名
    self.nameArr = nameMutable.copy;
    //列表id
    self.idArr = idMutable;
    //列表分类名
    self.categoriesNmaeArr = cateMutable.copy;
}
@end
